package dwz.common.util.web;

/**
 * <strong>PageBreakUtil</strong><br>
 * 页面分页工具类<br> 
 * <strong>Create on : 2012-1-5<br></strong>
 * <p>
 * <strong>Copyright (C) Ecointel Software Co.,Ltd.<br></strong>
 * <p>
 * @author peng.shi peng.shi@ecointel.com.cn<br>
 * @version <strong>Ecointel v1.0.0</strong><br>
 */
public class PageUtil
{
	public static PageInfo getPapination(PageInfo pageInfo,int totalCount){
		int numPerPage = pageInfo.getPageSize();
		int count = 0;
		if (totalCount > 0) {
			count = totalCount / numPerPage;
			if (totalCount % numPerPage > 0) {
				count++;
			}
		} else {
			totalCount = 0;
		}
		pageInfo.setTotalPages(Integer.valueOf(count));
		pageInfo.setPageNumShown(Integer.valueOf(count));
		pageInfo.setTotalItems(Integer.valueOf(totalCount));
		pageInfo.setStartIndex((pageInfo.getCurrentPage()-1)*pageInfo.getPageSize()+1);
		Integer endIndx = pageInfo.getCurrentPage()*pageInfo.getPageSize();
		pageInfo.setEndIndex(endIndx>totalCount?totalCount:endIndx);
		return pageInfo;
	}
}
